<template>
  <div class="DirectSellingProvince">
    <el-card class="box-card">
      <div slot="header" class="clearfix">
        <span style="line-height: 36px;">直销省份排名报表</span>
      </div>
      <s-table
        :table="table"
        @http="tableWatch">
        <el-form-item slot="multiSelect" label="多选操作" prop="multiSelect" v-if="table.multiSelect">
          <el-row>
            <el-col :span="8">
              <el-button size="small" type="info" @click="tableExport('')">多选导出</el-button>
            </el-col>
          </el-row>
        </el-form-item>
        <el-date-picker
          class="block"
          v-model="time"
          type="date"
          format="yyyy-MM-dd"
          @change="getTime"
          placeholder="请选择日期">
        </el-date-picker>
      </s-table>
    </el-card>
  </div>
</template>

<script>
  import {AutoVue} from '~/plugins/Tools';
  export default AutoVue({
    name: 'journaling_stockCountDaily-FEcarWms',
    head: {
      'title': '直销省份排名报表',
      'meta': [
        { 'hid': 'description', 'name': 'description', 'content': '乐速科技平台 直销省份排名报表 查看直销省份排名报表信息' },
      ],
    },
    data: {
      table: {
        column: [
          { label: '省份',
            prop: 'sheng',
            minWidth: '0px',
            search: true,
          },
          { label: '订单排名',
            prop: 'ddlpm',
            minWidth: '0px',
            search: true,
          },
          { label: '订单量',
            prop: 'ddl',
            minWidth: '0px',
            search: true,
          },
          { label: '销售额',
            prop: 'xse',
            minWidth: '0px',
            search: false,
          },
          { label: '订单量百分比',
            prop: 'ddlbfb',
            minWidth: '0px',
            search: false,
          },
          { label: '销售额占比',
            prop: 'xsezb',
            minWidth: '0px',
            search: false,
          },
        ],
        url: '',
        key: 'id',
        tableColumn: 6,
        option: {
          date: '',
        },
        summary: true,
      },
      time: '',
    },
    transition: 'slide-fade',
    methods: {
      tableExport (row) {
        let tableRef = 'table';
        let ids = [];
        if (row) {
          ids.push(row.id);
        } else {
          this[tableRef].multipleSelection.forEach(item => {
            ids.push(item.id);
          });
        }
        this.$confirm('您将导出直销省份排名报表数据。', '确认导出？', {
          confirmButtonText: '是',
          cancelButtonText: '否',
          type: 'warning',
        })
          .then(async _ => {
            try {
              let option = Object.assign({}, this['autoVue_' + tableRef]);
              await this.p({
                url: '/ExportController/SelectBathPrimaryExcel',
                method: 'post',
                responseType: 'blob',
                data: {
                  ids,
                  ...option,
                },
              });
            } catch (err) {
              console.log(err);
            }
          })
          .catch(_ => {
          });
      },
      getTime (date) {
        this.time = date;
        this.table.url = '/wmsprovincerankingreport/getWmsProvinceRankingReport';
        this.table.option.date = this.time;
        this.tableWatch('table');
      },
    },
    mounted: function () {
      // this.tableWatch('table');
    },
  });
</script>

<style scoped lang="scss">
  .block{
    margin: 10px auto;
  }
</style>

<style lang="scss">
  .DirectSellingProvince{
    width: 88vw;
    float: left;
  }
</style>
